package localizer.main;

import java.util.List;

import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.OverlayItem;

public class MapAppActivity extends MapActivity {

	MapView mapView;
	@Override
	public void onCreate(Bundle savedInstanceState) {    
		super.onCreate(savedInstanceState);    
		setContentView(R.layout.map_layout);
		mapView	 = (MapView) findViewById(R.id.mapview);    
		mapView.setBuiltInZoomControls(true);
		
		List<Overlay> mapOverlays = mapView.getOverlays();
		Drawable drawable = this.getResources().getDrawable(R.drawable.marker);
		MapOverlay itemizedoverlay = new MapOverlay(drawable, this);
		
		//Toast.makeText(this, getIntent().getExtras().getString("lat"), Toast.LENGTH_LONG).show();
		//Log.d("AKEEEEEEEEEEE", getIntent().getExtras().getString("lat"));
		if(Config.getInstance(getApplicationContext()).hasLoc(getApplicationContext())){
			int lat = (int) (Double.parseDouble(Config.getInstance(getApplicationContext()).getLat(getApplicationContext()).replaceAll(",", ".")) * 1000000);
			int longi = (int) (Double.parseDouble(Config.getInstance(getApplicationContext()).getLong(getApplicationContext()).replaceAll(",", ".")) * 1000000);
			GeoPoint point = new GeoPoint(lat,longi);
			OverlayItem overlayitem = new OverlayItem(point, Config.getInstance(getApplicationContext()).getPhone(getApplicationContext()),Config.getInstance(getApplicationContext()).getData(getApplicationContext()));
			mapView.getController().animateTo(point);
		
			itemizedoverlay.addOverlay(overlayitem);
			mapOverlays.add(itemizedoverlay);
		}
	}

	@Override
	protected boolean isRouteDisplayed() {
		return false;
	}

}
